;主程序
;编写者：陈科
;功能：定义数据段，打印功能菜单

PUBLIC  AUTH
PUBLIC  CRLF
PUBLIC  GA1
PUBLIC  GA2
PUBLIC  GAN
PUBLIC  ACTUAL
EXTRN  PRINTOUT:FAR
EXTRN  WORK6:FAR

NINE MACRO A
     LEA DX,  A
     MOV AH,9
     INT 21H
     ENDM;宏定义9号DOS调用

NINEK MACRO A
      LEA DX,A
      MOV AH,9
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H
      ENDM;宏定义调用，九号调用后输出一个回车换行

.386
STACK   SEGMENT USE16 STACK  'STACK'
             DB   200 DUP(0)
STACK   ENDS

DATA    SEGMENT USE16  PUBLIC  'DATA'
        BNAME  DB  'CHENKE',0,0
        IN_NAME  DB  10,?,10 DUP(0)
        BPASS  DB  '123456',0
        IN_PWD  DB  6,?,6 DUP(0)
        AUTH  DB  0
        CRLF  DB  0DH,0AH,'$'
        MENU1 DB  '1.LOAD/RELOAD$'
        MENU2 DB  '2.SEARCH GOOD$'
        MENU3 DB  '3.PLACE AN ORDER$'
        MENU4 DB  '4.RECOMMENDED DOGRAM$'
        MENU5 DB  '5.UNFINISHED$'
        MENU6 DB  '6.UNFINISHED$'
        MENU7 DB  '7.UNFINISHED$'
        MENU8 DB  '8.CS$'
        MENU9 DB  '9.EXIT$'

        LEAD1 DB  'IDENTITY:$'
        LEAD2 DB  'GOODNEW:$'

        LEAD3 DB  'PLEASE INPUT A CHOICE$'
        LEAD4 DB  'PLEASE INPUT NAME$'
        LEAD5 DB  'PLEASE INPUT PASSWORD$'
        LEAD6 DB  'PLEASE INPUT GOOD NAME$'

        LEAD7 DB  'THE LOAD MESSAAGE IS WRONG$'
        LEAD8 DB  'LOAD SUCCESSFULLY$'
        LEAD9 DB  'FIND GOOD SUCCESSFULLY$'
        LEADA DB  'NO GOOD$'
        LEADB DB  'WRONG NUMBER$'
        
        ACTUAL DB  10,?,10 DUP(0),0
        GOOD  DB  10,?,10 DUP(0),0
        N EQU  30
        SNAME DB  'SHOP$'
        GA1 DB  'PEN',0DH,6 DUP(0),10
            DW   35,56,70,25,0
        GA2 DB  'BOOK',0DH,5 DUP(0),9
            DW   12,30,25,5,0
        GAN DB  N-2 DUP('TEMPVALUE',0DH,8,15,0,20,30,0,2,0,0,0)
DATA ENDS

CODE  SEGMENT  USE16 PUBLIC  'CODE'
      ASSUME   CS:CODE,DS:DATA,SS:STACK
        STACKBAK        DB      608 DUP(0)
        EWAI            DW      0
        TOTALNUM        DW      608
        SETMIN          DB     '0','3'
        SETSEC          DB     '0','0'
        MIN             DB      ?,?
        SEC             DB      ?,?
        OLD_INT         DW      ?,?
        STATUS          DB      0
        MARK            DB      0

NEW08H  PROC    FAR
        PUSHF
        CALL    DWORD PTR CS:OLD_INT
        STI
        PUSHA
        PUSH    DS
        PUSH    ES
        MOV     MARK ,   1
        MOV     AX   ,   CS
        MOV     DS   ,   AX
        MOV     ES   ,   AX
        CALL    GET_TIME
        MOV     SI   ,  OFFSET MIN
        MOV     AX   ,   WORD PTR [SI]
        MOV     DI   ,  OFFSET SETMIN
        MOV     BX   ,   WORD PTR [DI]
        CMP     AX   ,   BX
        JNZ     FAIL
        MOV     SI   ,  OFFSET SEC
        MOV     AX   ,   WORD PTR [SI]
        MOV     DI   ,  OFFSET SETSEC
        MOV     BX   ,   WORD PTR [DI]
        CMP     AX   ,   BX
        JNZ     FAIL
        CMP     STATUS ,   0
        JNZ     ANOTHER
        MOV     STATUS ,   1
        MOV     BP   ,   0
        MOV     DI   , OFFSET STACKBAK
HOUHOU1: 
        MOV     DX   ,   [BP]
        MOV     [DI] ,   DX
        INC     DI
        INC     BP
        CMP     BP   ,   TOTALNUM
        JNZ     HOUHOU1
        MOV     AX   ,   SS
        MOV     EWAI ,   AX
        MOV     AX   ,   CS
        MOV     SS   ,   AX
        JMP     FAIL

ANOTHER:
        MOV     STATUS ,   0
        MOV     BP   ,   0
        MOV     SS   ,   EWAI
        MOV     DI   , OFFSET STACKBAK
HOUHOU2: 
        MOV     DX   ,   [DI]
        MOV     [BP] ,   DX
        INC     DI
        INC     BP
        CMP     BP   ,   TOTALNUM
        JNZ     HOUHOU2
        JMP     FAIL


FAIL:   
        POP     ES
        POP     DS
        POPA
        IRET
NEW08H  ENDP

GET_TIME        PROC
        MOV     AL   ,   0 ;访问秒
        OUT     70H  ,   AL
        JMP     $+2
        IN      AL   ,   71H
        MOV     AH   ,   AL
        AND     AL   ,   0FH
        SHR     AH   ,   4
        ADD     AX   ,   3030H
        XCHG    AH   ,   AL
        MOV     WORD PTR SEC , AX
        MOV     AL   ,   2 ;访问分
        OUT     70H  ,   AL
        JMP     $+2
        IN      AL   ,   71H
        MOV     AH   ,   AL
        AND     AL   ,   0FH
        SHR     AH   ,   4
        ADD     AX   ,   3030H
        XCHG    AH   ,   AL
        MOV     WORD PTR MIN , AX
        RET
GET_TIME        ENDP

START:
        PUSH    CS
        POP     DS
        MOV     AX   ,   3508H
        INT     21H
       MOV     OLD_INT ,   BX
       MOV     OLD_INT+2 , ES
       MOV     DX   ,   OFFSET NEW08H
       MOV     AX   ,   2508H
       INT     21H

      MOV AX,DATA
      MOV DS,AX
      MOV BP,0
  
MENU:             
            NINEK  <OFFSET LEAD1>
            MOV     AL  ,  [AUTH]
            ADD     AL  ,  30H
            MOV     DL  ,  AL
            MOV     AH  ,  2
            INT     21H
            NINE   <OFFSET CRLF>
            NINE   <OFFSET LEAD2>
            CMP     BP  ,  0
            JZ      FAK2
            NINE  <OFFSET ACTUAL+2>
FAK1:      
            NINE   <OFFSET CRLF>
            NINEK  <OFFSET MENU1>
            NINEK  <OFFSET MENU2>
            NINEK  <OFFSET MENU3>
            NINEK  <OFFSET MENU4>
            NINEK  <OFFSET MENU5>
            NINEK  <OFFSET MENU6>
            NINEK  <OFFSET MENU7>
            NINEK  <OFFSET MENU8>
            JMP     FAK3

FAK2:    MOV    DL   ,  '0'
            MOV    AH   ,   2
            INT    21H
            JMP    FAK1



FAK3:      
            NINEK  <OFFSET MENU9>
            NINEK  <OFFSET LEAD3>

            MOV  AH  ,  1
            INT     21H
            CMP   AL  ,  '1'
            JZ       STATE1
            CMP   AL  ,  '2'
            JZ       STATE2
            CMP   AL  ,  '3'
            JZ       STATE3
            CMP   AL  ,  '4'
            JZ       STATE4
            CMP   AL  ,  '5'
            JZ       STATE5
            CMP   AL  ,  '6'
            JZ       STATE6
            CMP   AL  ,  '7'
            JZ       STATE7
            CMP   AL  ,  '8'
            JZ       STATE8
            CMP   AL  ,  '9'
            JZ       STATE9
            JMP    MENU

STATE1:
       MOV SI,OFFSET BNAME
      LEA DX, LEAD4
      MOV AH,9
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H
      LEA DX,IN_NAME
      MOV AH,10
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H

      MOV CX,7
      MOV SI,OFFSET BNAME
      MOV DI,OFFSET IN_NAME+2
      MOV AL,[DI]
      CMP AL,0DH
      JZ  BACK
LOPA1:
      MOV AL,[SI]
      CMP AL,[DI]
      JNZ TOEND
      INC SI
      INC DI
      DEC CX
      CMP CX,0
      JNZ LOPA1
      MOV AL,[DI]
      CMP AL,'0'
      JNZ TOEND

      LEA DX,IN_PWD
      MOV AH,10
      INT 21H
      MOV DI,OFFSET IN_PWD+2
      MOV SI,OFFSET BPASS
      MOV CX,4
LOPA2:
      MOV AL,[SI]
      CMP AL,[DI]
      JNZ TOEND
      INC SI
      INC DI
      DEC CX
      CMP CX,0
      JNZ LOPA2
      MOV AL,[DI]
      CMP AL,'0'
      JNZ TOEND
      MOV AUTH,1
      LEA DX, LEAD8
      MOV AH,9
      INT 21H
      JMP MENU
BACK:
      MOV AUTH,0
      JMP MENU
TOEND:
      LEA DX, LEAD7
      MOV AH,9
      INT 21H
      JMP BACK

STATE2:
            LEA     DX  , LEAD6
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  GOOD
            MOV   AH ,  10
            INT     21H
              
            MOV  SI  , OFFSET GA1
            MOV   DI  , OFFSET GOOD+2
            MOV  CX ,  10
            MOV  BX ,  0
            MOV  DX ,  0
LOPA3:      
            MOV  AL  ,  [SI]
            CMP   AL  ,  [DI]
            JNZ    TOAGAIN
            INC    SI
            INC    DI
            DEC   CX
            CMP  CX  ,  0
            JNZ    LOPA3
            LEA     DX  , LEAD9
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            MOV  SI ,OFFSET GA1
            MOV DI ,OFFSET GOOD+2
            MOV    CX  ,   -21
            INC    BX
ST1:      
            ADD    CX  ,   21
            DEC    BX
            CMP    BX  ,   0
            JNZ    ST1
            ADD  SI , CX
            MOV  BP, SI
            MOV  DI  ,   OFFSET ACTUAL +2
ST2:      MOV  AX  ,   [SI]
            MOV  [DI],   AX
            ADD  SI  ,   2
            ADD  DI  ,   2
            CMP  AX  ,   0
            JNZ ST2   
            MOV  BYTE PTR [DI] , '$'
            JMP    MENU

TOAGAIN:    
            MOV  SI , OFFSET GA1
            MOV DI ,OFFSET GOOD+2
            INC   BX
            ADD   DX , 21
            ADD  SI , DX
            CMP BX , N
            JNZ    LOPA3
            LEA     DX  , LEADA
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            MOV   BP , 0
            JMP    MENU

STATE3:
            CMP BP  ,  0
            JZ     TOEND2
            MOV  SI  ,  BP
            ADD   SI  ,  17
            MOV  AX ,  [SI]
            INC    AX
            MOV  [SI] , AX
            JMP   STATE4

TOEND2:     
            LEA     DX  ,LEAD9
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            JMP    MENU

STATE4:
            MOV     SI  , OFFSET  GA1
            MOV     DI  ,   0
            MOV     DX  ,   0

ST3:        
            CALL     F4
            INC       DI
            CMP     DI  ,   N
            JNZ      LOPA4
            JMP     MENU

LOPA4:      
            MOV     SI  , OFFSET  GA1
            MOV     AX  ,   DI
            MOV     DX  ,   0
ST4:      
            DEC     AX
            ADD     DX  ,   21
            CMP     AX  ,   0
            JNZ     ST4
            ADD     SI  ,   DX
            JMP     ST3

STATE5:
            JMP MENU

STATE6:
            CALL   WORK6
            JMP MENU

STATE7:
             INT 08H
            JMP MENU

STATE8:
            MOV     CX  ,   CS
            MOV     BX  ,   CX
            AND     BX  ,   0F000H
            SHR     BX  ,   12
            MOV     SI  ,   4
LOPA5:      
            DEC     SI
            CMP     BL  ,   0AH
            JAE     LOPA7
            ADD     BX  ,   30H
LOPA6:      
            MOV     DX  ,   BX
            MOV     AH  ,   2
            INT     21H
            CMP     SI  ,   0
            JNZ     LOPA8
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            JMP     MENU
LOPA7:      
            ADD     BX  ,   55
            JMP     LOPA6
LOPA8:      
            SHL     CX  ,   4
            MOV     BX  ,   CX
            AND     BX  ,   0F000H
            SHR     BX  ,   12
            JMP     LOPA5

STATE9:
            LDS    DX   , DWORD PTR OLD_INT
            MOV    AX   ,   2508H
            INT    21H
FJ1:    
            MOV    AH   ,   4CH
            INT      21H 


F4       PROC
            MOV     AL  ,   [SI+11]
            MOV     AH  ,   [SI+12]
            MOV     BX  ,   128
            IMUL    BX
            MOV     DX  ,   0
            MOV     BL  ,   [SI+13]
            MOV     BH  ,   [SI+14]
            IDIV    BX
            MOV     CX  ,   AX
            MOV     AL  ,   [SI+17]
            MOV     AH  ,   [SI+18]
            MOV     BX  ,   64
            IMUL    BX
            MOV     DX  ,   0
            MOV     BL  ,   [SI+15]
            MOV     BH  ,   [SI+16]
            IDIV    BX
            MOV     DX  ,   AX
            ADD     CX  ,   DX
            MOV     [SI+19] ,   CL
            MOV     [SI+20] ,   CH
            RET
F4      ENDP

CODE ENDS
           END START